<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">记录编号</label>
        <el-input v-model="query.associateDcsItemId" clearable placeholder="记录编号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">DCS需求单号</label>
        <el-input v-model="query.dcsRequireOrderCode" clearable placeholder="DCS需求单号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">产线编码</label>
        <el-input v-model="query.productLineCode" clearable placeholder="产线编码" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">物料编码</label>
        <el-input v-model="query.materialCode" clearable placeholder="物料编码" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="记录编号" prop="associateDcsItemId">
            <el-input v-model="form.associateDcsItemId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="DCS需求单号" prop="dcsRequireOrderCode">
            <el-input v-model="form.dcsRequireOrderCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="产线编码" prop="productLineCode">
            <el-input v-model="form.productLineCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="物料编码" prop="materialCode">
            <el-input v-model="form.materialCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="需求数量" prop="requireNum">
            <el-input v-model="form.requireNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="已生成数量" prop="generateNum">
            <el-input v-model="form.generateNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="已完成数量" prop="completeNum">
            <el-input v-model="form.completeNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="下发时间" prop="dispatchTime">
            <el-input v-model="form.dispatchTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="开始时间" prop="startTime">
            <el-input v-model="form.startTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="完成时间" prop="finishTime">
            <el-input v-model="form.finishTime" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <!-- <el-table-column type="selection" width="55" /> -->
        <el-table-column prop="associateDcsItemId" label="记录编号" />
        <el-table-column prop="dcsRequireOrderCode" label="DCS需求单号" />
        <el-table-column prop="productLineCode" label="产线编码" />
        <el-table-column prop="materialCode" label="物料编码" />
        <el-table-column prop="requireNum" label="需求数量" />
        <el-table-column prop="generateNum" label="已生成数量" />
        <el-table-column prop="completeNum" label="已完成数量" />
        <el-table-column prop="dispatchTime" label="下发时间" />
        <el-table-column prop="startTime" label="开始时间" />
        <el-table-column prop="finishTime" label="完成时间" />
        <el-table-column v-if="checkPer(['admin','dcsRequireOrderRecord:edit','dcsRequireOrderRecord:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="checkDetail(scope.row)">查看详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudDcsRequireOrderRecord from '@/api/work/dcsRequire'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
// import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, associateDcsItemId: null, dcsRequireOrderCode: null, productLineCode: null, materialCode: null, requireNum: null, generateNum: null, completeNum: null, dispatchTime: null, startTime: null, finishTime: null }
export default {
  name: 'DcsRequire',
  components: { pagination, crudOperation, rrOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: 'dcs_require_order_record', url: 'api/dcsRequireOrderRecord', idField: 'id', sort: 'id,desc', crudMethod: { ...crudDcsRequireOrderRecord },
      optShow: {
        add: false,
        edit: false,
        download: true,
        reset: true,
        del: false
      }
    })
  },
  data() {
    return {
      permission: {
        add: ['admin', 'dcsRequireOrderRecord:add'],
        edit: ['admin', 'dcsRequireOrderRecord:edit'],
        del: ['admin', 'dcsRequireOrderRecord:del']
      },
      rules: {
        associateDcsItemId: [
          { required: true, message: '记录编号不能为空', trigger: 'blur' }
        ],
        dcsRequireOrderCode: [
          { required: true, message: 'DCS需求单号不能为空', trigger: 'blur' }
        ],
        productLineCode: [
          { required: true, message: '产线编码不能为空', trigger: 'blur' }
        ],
        materialCode: [
          { required: true, message: '物料编码不能为空', trigger: 'blur' }
        ],
        requireNum: [
          { required: true, message: '需求数量不能为空', trigger: 'blur' }
        ],
        generateNum: [
          { required: true, message: '已生成数量不能为空', trigger: 'blur' }
        ],
        completeNum: [
          { required: true, message: '已完成数量不能为空', trigger: 'blur' }
        ],
        dispatchTime: [
          { required: true, message: '下发时间不能为空', trigger: 'blur' }
        ],
        startTime: [
          { required: true, message: '开始时间不能为空', trigger: 'blur' }
        ],
        finishTime: [
          { required: true, message: '完成时间不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'associateDcsItemId', display_name: '记录编号' },
        { key: 'dcsRequireOrderCode', display_name: 'DCS需求单号' },
        { key: 'productLineCode', display_name: '产线编码' },
        { key: 'materialCode', display_name: '物料编码' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    checkDetail(item) {
      this.$router.push(`/dcsManagement/dcsRequireDetail?dcsRequireOrderCode=${item.dcsRequireOrderCode}`)
    }
  }
}
</script>

<style scoped>

</style>
